# 1.获取网页的源码
# 2.解析 解析的服务器响应的文件 etree.HTML
# 3.打印

import urllib.request
from lxml import etree

url = "https://www.baidu.com"
headers = {
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36'
}
request = urllib.request.Request(url=url, headers=headers)

response = urllib.request.urlopen(request)
html = response.read().decode("utf-8")
# print(html)

# 使用xpath 解析
tree = etree.HTML(html)
text = tree.xpath('//input[@id="su"]/@value')  # xpath 返回的是一个列表数据
print(text[0])
